package com.learn.greedy;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 贪心案例2：
 * 最好的办公室安排
 * 需求，安排一天内的会议，使一天内的会议场数最多
 *
 * 按会议结束时间来安排使最有解
 */
public class BestArrange {
    public static class Program {
        private int startTime;
        private int endTime;

        public Program(int startTime, int endTime) {
            this.startTime = startTime;
            this.endTime = endTime;
        }
    }

    public static class ProgramComparator implements Comparator<Program> {

        @Override
        public int compare(Program o1, Program o2) {
            return o1.endTime - o2.endTime;
        }
    }


    public int getMaxArrange(Program[] programs) {
        int timeLine = 0;
        int res = 0;
        Arrays.sort(programs, new ProgramComparator());
        for (int i = 0; i < programs.length; i++) {
            if (timeLine <= programs[i].startTime) {
                res++;
                timeLine = programs[i].endTime;
            }
        }
        return res;
    }
}
